<script setup>
import { ref, onMounted, computed } from 'vue'
import { useRouter } from 'vue-router'
// 路由
const router = useRouter()
// 返回主页
const goToHome = () => {
  router.push('/')
}
// 进度条模拟数据
const progress = ref(0)

// 全选状态
const selectAll = ref(false)


const showPictureArea = ref(false)

// 缩略图数据
const thumbnails = ref([])

// 模拟进度变化
const simulateProgress = () => {
  const interval = setInterval(() => {
    if (progress.value < 100) {
      progress.value += 10
    } else {
      clearInterval(interval)
    }
  }, 1000)
}

onMounted(() => {
  simulateProgress()
  updateTime()
  setInterval(updateTime, 1000)
})
const goToModelTraining = () => {
  router.push('/model-training')
}
const goToInferenceDemo = () => {
  router.push('/inference-demo')
}

// 获取当前时间
const currentTime = ref('')

// 更新时间的函数
const updateTime = () => {
  const now = new Date()
  const year = now.getFullYear()
  const month = String(now.getMonth() + 1).padStart(2, '0')
  const day = String(now.getDate()).padStart(2, '0')
  const hours = String(now.getHours()).padStart(2, '0')
  const minutes = String(now.getMinutes()).padStart(2, '0')
  const seconds = String(now.getSeconds()).padStart(2, '0')
  currentTime.value = `${year}年${month}月${day}日 ${hours}:${minutes}:${seconds}`
}

// 按钮状态
const buttonStates = ref({
  modelTraining: 'normal',
  inferenceDemo: 'normal',
  home: '正常',
  user: '正常',
  nextStep: 'normal',
  prevStep: 'normal',
  startTrain: 'normal'
})

// 鼠标事件处理
const handleMouseEnter = (button) => {
  buttonStates.value[button] = '悬浮'
}

const handleMouseLeave = (button) => {
  buttonStates.value[button] = '正常'
}

const handleMouseDown = (button) => {
  buttonStates.value[button] = '点击'
}

const handleMouseUp = (button) => {
  buttonStates.value[button] = '悬浮'
}

onMounted(() => {
//   initCharts()
  // 模拟数据更新
//   setInterval(updateData, 1000)
  updateTime()
  // 每秒更新一次时间
  setInterval(updateTime, 1000)
})
</script>

<template>
  <div class="model-training-container">
    
    
    
    <!-- 主内容区域 -->
    <div class="main-content">
      <!-- 顶部栏 -->
      <div class="top-bar">
        <div class="system-name">算筹平台系统</div>
        <div class="home-button"
             @mouseenter="handleMouseEnter('home')"
             @mouseleave="handleMouseLeave('home')"
             @mousedown="handleMouseDown('home')"
             @mouseup="handleMouseUp('home')"
             @click="goToHome">
          <img :src="`/pic/dataManagement/首页-${buttonStates.home}.png`" alt="首页">
        </div>
        <div class="current-time">{{ currentTime }}</div>
        <div class="user-info">
          <div class="user-button"
               @mouseenter="handleMouseEnter('user')"
               @mouseleave="handleMouseLeave('user')"
               @mousedown="handleMouseDown('user')"
               @mouseup="handleMouseUp('user')">
            <img :src="`/pic/dataManagement/用户-${buttonStates.user}.png`" alt="用户">
          </div>
          <span class="username">用户：XXXX</span>
        </div>
      </div>
      
      <!-- 内容区域 -->
      <div class="content-area">
        <!-- 进度条 -->
        <div class="progress-section">
          <div class="progress-bar">
            <div class="progress" :style="{ width: progress + '%' }"></div>
          </div>
          <div class="progress-text">{{ progress }}%</div>
        </div>
        
        <!-- 缩略图区域 -->
        <div class="thumbnail-area" v-if="showPictureArea">
          <div class="select-all">
            <input type="checkbox" id="selectAll" v-model="selectAll">
            <label for="selectAll">全选</label>
          </div>
          
          <div class="thumbnails">
            <div class="thumbnail-item" v-for="(item, index) in thumbnails" :key="index">
              <input type="checkbox" :id="'thumb' + index" v-model="item.selected">
              <label :for="'thumb' + index">
                <img :src="item.src" :alt="'缩略图' + index">
              </label>
            </div>
          </div>
        </div>

        <div class="video-area" v-if="!showPictureArea">
          <video controls width="100%" style="max-width: 800px; margin: 0 auto; display: block;">
            <source src="" type="video/mp4">
            您的浏览器不支持HTML5视频播放
          </video>
        </div>

        
        <!-- 导出按钮 -->
        <div class="export-button">
          <button @click="exportImages">导出</button>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped>

.progress-section {
  margin-bottom: 20px;
}

.progress-bar {
  width: 100%;
  height: 20px;
  background-color: #f0f0f0;
  border-radius: 10px;
  overflow: hidden;
}
.model-training-container {
  display: flex;
  width: 100%;
  height: 100vh;
  background-color: #f0f2f5;
}

.sidebar {
  width: 80px;
  background-color: #4a6baf;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 20px;
}

.logo img {
  width: 60px;
  height: auto;
}

.nav-buttons {
  margin-top: 20px;
}

.nav-button {
  margin-bottom: 10px;
  cursor: pointer;
}

.nav-button img {
  width: 60px;
  height: auto;
}
/* .sidebar-button {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 20px;
  cursor: pointer;
  color: white;
} */

/* .sidebar-button img {
  width: 40px;
  height: 40px;
  margin-bottom: 5px;
} */


/* 主内容区域样式 */
.progress-section {
  margin: 20px 0;
  display: flex;
  align-items: center;
}

.progress-bar {
  flex: 1;
  height: 20px;
  background-color: #f0f0f0;
  border-radius: 10px;
  overflow: hidden;
}

.progress {
  height: 100%;
  background-color: #4CAF50;
  transition: width 0.3s;
}

.progress-text {
  margin-left: 10px;
  min-width: 50px;
}

.thumbnail-area {
  margin: 20px 0;
  border: 1px solid #ddd;
  padding: 10px;
  border-radius: 5px;
}

.select-all {
  margin-bottom: 10px;
}

.thumbnails {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}

.thumbnail-item {
  position: relative;
}

.thumbnail-item img {
  width: 100%;
  height: auto;
  border: 1px solid #ddd;
  border-radius: 3px;
}

.export-button {
  margin-top: 20px;
  text-align: center;
}

.export-button button {
  padding: 8px 20px;
  background-color: #4a6baf;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.export-button button:hover {
  background-color: #3a5a9f;
}
.info-section {
  margin-bottom: 20px;
  padding: 15px;
  background-color: #f8f9fa;
  border-radius: 5px;
}

.info-item {
  margin-bottom: 10px;
}

.label {
  font-weight: bold;
  margin-right: 10px;
}


.confirm-button {
  width: 120px;
  height: 40px;
  line-height: 40px;
  text-align: center;
  background-color: #1890ff;
  color: white;
  border-radius: 5px;
  cursor: pointer;
  margin: 0 auto;
}

.confirm-button:hover {
  background-color: #40a9ff;
}

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
}



/* 内容区域样式 */
.content-area {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  position: relative;
}

/* 标题区域样式 */
.title-area {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.title {
  display: flex;
  align-items: center;
}

.title img {
  width: 30px;
  height: 30px;
  margin-right: 10px;
}

.title span {
  font-size: 18px;
  font-weight: bold;
}

.top-bar {
  height: 60px;
  background-color: white;
  display: flex;
  align-items: center;
  padding: 12px 20px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.system-name {
  font-size: 20px;
  font-weight: bold;
  color: #333;
}

.home-button {
  margin-left: 20px;
  cursor: pointer;
}

.current-time {
  margin-left: auto;
  color: #666;
}

.user-info {
  display: flex;
  align-items: center;
  margin-left: 20px;
}

.user-button {
  cursor: pointer;
  margin-right: 10px;
}

.username {
  color: #333;
}
</style>